package live.zs;

import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.map.IMap;

import java.util.Map;


/**
 * @author madison
 * @description
 * @date ${DATE} ${TIME}
 */
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
//        writeData();
        readData();
    }


    public static void writeData() {
        ClientConfig clientConfig = new ClientConfig();
        clientConfig.setClusterName("madison-cluster-name");

        HazelcastInstance instance = HazelcastClient.newHazelcastClient(clientConfig);
        IMap<String, String> map = instance.getMap("my-distributed-map");

        map.put("1", "John");
        map.put("2", "Mary");
        map.put("3", "Jane");
        map.put("4", "Madison");

        instance.shutdown();
    }

    public static void readData() {
        ClientConfig clientConfig = new ClientConfig();
        clientConfig.setClusterName("madison-cluster-name");

        HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);


        IMap<String, String> map = client.getMap("my-distributed-map");
        for (Map.Entry<String, String> entry : map.entrySet()) {
            System.out.println(entry.getKey() + " " + entry.getValue());
        }

        client.shutdown();
    }
}